package com.hsu.project.service.impl.inner;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hsu.project.common.ErrorCode;
import com.hsu.project.exception.BusinessException;
import com.hsu.project.mapper.UserMapper;
import com.hsu.yuapicommon.model.entity.User;
import com.hsu.yuapicommon.service.InnerUserService;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;

import javax.annotation.Resource;

/**
 * @ClassName: InnerUserServiceImpl
 * @author Hsu琛君珩
 * @date 2024-09-02
 * @apiNote
 * @Version: v1.0
 */
@DubboService
public class InnerUserServiceImpl implements InnerUserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 根据密钥获取用户内部信息
     * @param accessKey
     * @return 内部用户信息，如果找不到匹配的就返回 null
     */
    @Override
    public User getInvokeUser(String accessKey) {
        // 参数校验
        if (StringUtils.isAnyBlank(accessKey)) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        // 查询
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("accessKey", accessKey);
        // 通过 selectOne 获取用户信息
        return userMapper.selectOne(queryWrapper);
    }
}
